﻿<!DOCTYPE html>
<!--计划隐患上报-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <!--<link href="/static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="/static/js/vue-treeselect/vue-treeselect.js"></script>-->
    <style>
        body {
            padding-bottom: 10px;
        }
        /*说明：
         由于mystyle.css中162行.el-form-item__content {line-height: normal!important;}导致的
         index.css中.el-form-item--mini .el-form-item__content, .el-form-item--mini .el-form-item__label{    line-height: 28px;}失效
         但出于无法修改样式表的情况，所以在该页面添加以下样式，以保证页面内标题和内容不偏离
        */
        .el-form-item--mini .el-form-item__content,
        .el-form-item--mini .el-form-item__label {
            line-height: 28px !important;
        }
    </style>
    <style>
        .el-link span {
            line-height: 28px;
        }
    </style>
    <style>
    </style>
</head>
<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini" label-position="right" style="padding-bottom:10px;">
            <el-row>
                <el-col :span="9">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        <div> {{RisksManagement.RiskReport.RiskRegion+mark.m}}</div>
                                    </template>
                                    <el-select @visible-change="visibleChange" v-model="Form.RiskRegion" slot="suffix" :placeholder="RisksManagement.RiskReport.RiskRegion" @change="getNext($event)">
                                        <el-option label="请选择" value=""></el-option>
                                        <el-option v-for="item in RiskRegion" :label="item.label" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col :span="9" offset="1">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        <div> {{RisksManagement.RiskReport.RiskPosition+mark.m}}</div>
                                    </template>
                                    <el-select @visible-change="visibleChange" v-model="Form.RiskPosition" slot="suffix" :placeholder="RisksManagement.RiskReport.RiskPosition">
                                        <el-option label="请选择" value=""></el-option>
                                        <el-option v-for="item in RiskPosition" :label="item.label" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col :span="4" offset="1">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-button type="primary" @click="onSelectContent" style="height:28px;margin:1px 0 0 5px;">{{col.btnSelectContent}}</el-button>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>

            </el-row>


            <el-row>
                <el-col :span="11">
                    <el-form-item :label="RisksManagement.RiskContent.Unit+mark.m" prop="Unit">
                        <span>
                            {{Form.Unit}}
                        </span>
                    </el-form-item>
                </el-col>
                <el-col :span="11" offset="2">
                    <el-form-item :label="RisksManagement.RiskContent.Objective+mark.m" prop="Objective">
                        {{Form.Objective}}
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <el-form-item :label="RisksManagement.RiskContent.PersonInCharge+mark.m" prop="PersonInCharge">
                        {{Form.PersonInCharge}}
                    </el-form-item>
                </el-col>
                <el-col :span="11" offset="2">
                    <el-form-item :label="RisksManagement.RiskContent.Participant+mark.m" prop="Participant">
                        {{Form.Participant}}
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item :label="RisksManagement.RiskContent.Requirements+mark.m" prop="Requirements">
                        {{Form.Requirements}}
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item :label="RisksManagement.RiskContent.Content+mark.m" prop="Content">
                        {{Form.Content}}
                    </el-form-item>
                </el-col>
            </el-row>















            <el-form :inline="true">
                <el-row type="flex" justify="begin">

                    <el-form-item>
                        <el-button type="primary" @click="InputInput('tj')">{{col.btnAdd}}</el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="danger" @click="onDelete">{{col.btnDelete}}</el-button>
                    </el-form-item>


                </el-row>
            </el-form><!--ListItem.tableHeight-->
            <el-table stripe ref="table" :data="ListItem.tableData" :row-key="getRowKeys" :height="400" border
                      @selection-change="handleSelectionChange" :span-method="objectSpanMethod" row-style="height:10px" style="width: 100%;margin:0 auto;margin-bottom:20px;">
                <el-table-column type="selection"
                                 style="padding-top: 0px;padding-bottom: 0px;"
                                 align="center"
                                 width="55"
                                 :reserve-selection="true">
                </el-table-column>
                <el-table-column prop="Project" :label="RisksManagement.RiskContent.Project">
                </el-table-column>
                <el-table-column prop="Region" :formatter="getDicValue" :label="RisksManagement.RiskContent.Region">
                </el-table-column>
                <el-table-column prop="Remark" :label="RisksManagement.RiskContent.Remark">
                </el-table-column>
                <el-table-column prop="Standard.data" :label="RisksManagement.RiskContent.Standard">
                </el-table-column>
                <el-table-column prop="RiskLevel" :formatter="getDicValue" :label="RisksManagement.RiskContent.RiskLevel" width="100">
                </el-table-column>
                <el-table-column width="200" prop="update" :label="col.stWork" fixed="right">
                    <template slot-scope="scope">
                        <!--<button type="button" class="elst-bt-xg" @click=InputInput('xg',scope.row.id)>
                            <i class="el-icon-edit"></i>300 500 600 900
                        </button>-->
                        <el-col :span="16">
                            <el-select @visible-change="visibleChange" v-model="scope.row.SelectStatus" size="mini">
                                <el-option v-for="item in Control" :label="item.value" :value="item.key">
                                </el-option>
                            </el-select>
                        </el-col>
                        <el-col :span="6" offset="2">
                            <el-link type="primary"
                                     style="color:#409eff;cursor:pointer;"
                                     v-if="scope.row.SelectStatus=='115002'?true:false"
                                     @click="ReportInput(scope.row.id,scope.row.Standard.name)">{{col.btnReport}}</el-link>
                        </el-col>
                    </template>
                </el-table-column>

            </el-table>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog :title="dialogTitle" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        //Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                dialogTitle: '选择排查内容',
                //父业传参
                id: '',
                //业务表单内容
                ListItem: ListItem,
                mydata: PersonInChargeTree,
                Region: myTree,
                Form: {
                    id: guidEmpty,
                    RiskRegion: '',
                    RiskPosition: '',
                    Unit: '',//排查单位
                    Objective: '',//排查目的
                    PersonInCharge: null,//负责人
                    Participant: null,//参与人员
                    Content: '',//排查内容
                    Requirements: '',//排查要求
                    Plan: '',
                    ReportType: '102001',//计划隐患上报
                    InputTable: null,
                },
                RiskRegion: [],
                RiskPosition: [],
                spanArr: [],
                Control: [],
                //表单验证
                rules: {}
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //添加
                InputInput: function () {
                    this.dialogTitle = '添加';
                    //this.ListItem.InputUrl = "PlanReportInputReport.html?id=" + id + "&name=" + name + "&t=" + Date.parse(new Date());
                    //this.ListItem.dialogVisible = true;

                    var url = "../RiskContentEditStandardType.html";
                    this.ListItem.InputUrl = url + "?pid=" + this.Form.id + "&api=RiskReport&t=" + Date.parse(new Date());
                    this.ListItem.dialogVisible = true;
                },
                //上报，id为父级数据id，name为当前数据编号
                ReportInput: function (id, name) {
                    console.log(id)
                    console.log(name)

                    this.dialogTitle = '上报';
                    DialogShow(this, 'tj', "RiskReportInput.html", id);
                    //this.ListItem.InputUrl = "RiskReportInput.html?id=" + id + "&name=" + name + "&t=" + Date.parse(new Date());
                    //this.ListItem.dialogVisible = true;
                },
                //二级联动
                getNext: function (prov) {
                    this.RiskPosition = [];
                    this.Form.RiskPosition = '';
                    this.RiskPosition = fn(this.Region, prov);

                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/RiskReport/SavePlanReport', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                //获取input数据
                getData: function () {
                    var mythis = this;

                    //getData(mythis, '/api/RiskContent/get?id=' + mythis.id);

                    //二级联动赋值
                    mythis.RiskPosition = [];
                    mythis.RiskPosition = fn(mythis.Region, mythis.Form.RiskRegion);

                    //格式化名字
                    mythis.Form.PersonInCharge = mythis.formatName(mythis.Form.PersonInCharge);
                    mythis.Form.Participant = mythis.formatName(mythis.Form.Participant);
                },
                //选择排查内容
                onSelectContent: function () {
                    this.dialogTitle = '选择排查内容'
                    this.ListItem.InputUrl = "PlanReportInputSelect.html?region=" + this.Form.RiskRegion + "&position=" + this.Form.RiskPosition + "&t=" + Date.parse(new Date());
                    this.ListItem.dialogVisible = true;
                },
                //以下是该input内的表格方法
                //表格数据格式化
                getDicValue: function (row, column, cellValue, index) {
                    switch (column.property) {
                        case "Region":
                            return getTreeValue(this.Region, cellValue)
                            break;
                        case "RiskLevel":
                            return getDicValue('03', cellValue)
                            break;
                        default:
                    }

                },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //合并行
                objectSpanMethod: function (row, column, rowIndex, columnIndex) {
                    //声明列对象，行对象
                    var columnIndex = row.columnIndex, rowIndex = row.rowIndex
                    //判断需要合并的列
                    if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2 || columnIndex === 3) {
                        //读取当前行的合并数量
                        var _row = this.spanArr[rowIndex];
                        //console.log('输出合并行序列',rowIndex, _row)
                        //如果当前行合并，则对应列为1，否则0（0为不显示）
                        var _col = _row > 0 ? 1 : 0;
                        return [_row, _col]
                    }
                },
                //删除方法(Comm中没有适配的delete方法，故仿写一份)
                //（遗留问题2：删除后，合并行方案未更新，导致剩余的新内容合并错误，例：32432，删除第一行后应变为2432，但实际为3243，或32432删除第二行应为3432，但实际依旧是3243
                //原计划为重新调用合并行方法，但依旧存在问题）
                onDelete: function () {
                    var mythis = this;
                    var url = '/api/RiskReport/DeleteInputTable';
                    if (mythis.ListItem.tableMultipleSelection.length == 0) {
                        showMessage(msg.AtLeastOne, 'error')
                        return;
                    }
                    mythis.$confirm(' 是否确认继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        var delIds = [];
                        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
                            var item = mythis.ListItem.tableMultipleSelection[i];
                            delIds.push(item.id);
                        }
                        myAjax("post", mythis, url, delIds, function (response) {
                            mythis.getData();
                            mythis.ListItem.tableData = mythis.Form.InputTable;
                            mythis.getSpanArr(mythis.ListItem.tableData);
                            showMessage(msg.OperatingOk, "success");
                        });
                    }).catch(function () {
                        showMessage("已取消删除!");
                    });
                },
                //合并行方法
                getSpanArr: function (data) {
                    //生成合并行数据组
                    this.spanArr = [];
                    var spanArr = this.spanArr;
                    //console.log('Begin', this.spanArr);
                    //初始化行号
                    var c = 0;
                    //遍历数据
                    //this.ListItem.tableData.forEach(function (v, i) {
                    data.forEach(function (v, i) {
                        //第一条数据固定
                        if (i === 0) {
                            spanArr.push(1);
                        }
                        else {
                            //如果当前数据跟上一条数据id相同，则合并行数据+1，并且填充0合并行
                            if (v.id === data[i - 1].id) {
                                spanArr[c] += 1;
                                spanArr.push(0);
                            }
                            else {
                                //如果不相同，则重置合并数量，且更改合并行数据组索引
                                spanArr.push(1);
                                c = i;
                            }
                        }
                    })
                    //console.log('End', this.spanArr);
                },
                closeDialog: function () {
                    this.getData();
                    console.log(this.Form)
                    //console.log(this.Form.InputTable)
                    this.ListItem.tableData = this.Form.InputTable;
                    this.getSpanArr(this.ListItem.tableData);
                },
                formatName: function (cellValue) {
                    if (cellValue) {
                        if (typeof cellValue === 'string' || typeof cellValue === 'number') {
                            return getTreeValue(this.mydata, cellValue)
                        }
                        else {
                            var result = '';
                            for (var i = 0; i < cellValue.length; i++) {
                                result += getTreeValue(this.mydata, cellValue[i]) + ',';
                            }
                            result = result.substr(0, result.length - 1);
                            return result;
                        }
                    }
                }
            },
            mounted: function () {
                //绑定下拉和tree
                this.RiskRegion = fn(this.Region, "0");
                this.Control = getDicData('115');//字典内容
                //读取数据
                //this.getData();
            }
        });
    </script>
</body>

</html>